﻿using System;
using System.Collections.Generic;
using DataAccessLibrary.DAL;
using entities;

namespace BusinessLogicLibrary
{
    public class SupplyModule
    {
        private readonly SupplyDAO _supplyDAO = new SupplyDAO();

        public bool AddSupplyDetail(bool available, string supplyName, decimal price, string unit)
        {
            if (supplyName.Trim() == "" || unit == "")
            {
                throw new ArgumentNullException();
            }
            var supplyDetail = new SupplyDetail
                                   {
                                       Available = available,
                                       SupplyName = supplyName,
                                       SupplyPrice = price,
                                       Unit = unit
                                   };
            return _supplyDAO.InsertSupplyDetail(supplyDetail);
        }

        public List<SupplyDetail> GetSupplyDetail(bool available)
        {
            return available ? _supplyDAO.SelectSupplyDetail(1) : _supplyDAO.SelectSupplyDetail(-1);
        }

        public SupplyDetail GetSupplyDetailByID(int id)
        {
            return _supplyDAO.SelectSupplyDetailByID(id);
        }

        public List<SupplyDetail> GetSupplyDetailByName(string name)
        {
            return _supplyDAO.SearchSupplyDetailByName(name);
        }

        public bool ModifySupplyDetail(int id, bool available, string supplyName, decimal price, string unit)
        {
            if (supplyName.Trim() == "" || unit == "")
            {
                throw new ArgumentNullException();
            }
            var supplyDetail = new SupplyDetail
                                   {
                                       SupplyDetailID = id,
                                       Available = available,
                                       SupplyName = supplyName,
                                       SupplyPrice = price,
                                       Unit = unit
                                   };
            return _supplyDAO.UpdateSupplyDetail(supplyDetail);
        }
    }
}